<template>
  <div class="report">
    <van-sticky>
      <div class="reportTop">
        <div class="reportTabs">
        <span v-for="(lab, k) in tabList" :key="k"  @click="goToAnchor(k)"
              :class="tabActiveIndex== k?'acTab':''" :ref="'tab'+k">{{lab}}</span>
        </div>
      </div>
    </van-sticky>
    <PingGu v-show="tabActiveIndex===0"></PingGu>
    <KangYang v-show="tabActiveIndex===1" :doLoad="tabLoads[1]" @fatherLoad="tabLoads[1] = false"></KangYang>
    <HealthRecord v-if="tabActiveIndex===2" :dataJson="saveJsonData" @saveData="saveData" :msg="state"></HealthRecord>
    <div style="height: 30px"></div>
  </div>
</template>

<script lang="ts" setup>
import PingGu from './components/pinggu.vue';
import KangYang from './components/kangyang.vue';
import HealthRecord from './components/healthRecord.vue';
import { reactive, onMounted, toRaw, ref } from "vue";
import { useRoute } from 'vue-router';
let tabList = reactive(['三济评估', '三济康养', '健康记录']);
let tabLoads = reactive([false, false, false]);
let state = reactive({msg: 1})
let saveJsonData = reactive({
  getDietDayRecord: {},
  getDietWeekRecord: {}
});
let tabActiveIndex = ref(0);
let goToAnchor = (index) => {
  window.scrollTo(0,0)
  if (tabActiveIndex.value!==index) {
    tabActiveIndex.value = index
    if (!tabLoads[index]) {
      tabLoads[index] = true
    }
  }
}
let saveData = (data, acTab) => {
  saveJsonData[acTab] = data
  state.msg += 1
}
onMounted(()=>{
  const route = useRoute();
  let appKey = route.query.appKey as string;
  localStorage.setItem('appKey', appKey);
})

</script>

<style scoped lang="scss">
.report{
  .reportTop{
    width: 100%;
    height: 58px;
    overflow: hidden;
    //box-shadow: 0px 5px 11px 0px rgba(128,162,191,0.16);
    //border-bottom: 1px solid rgba(255, 255, 255, 0.63);
  }
  .reportTabs {
    color: rgba(34, 34, 34, .7);
    font-size: 14px;
    height: 68px;
    line-height: 58px;
    background: #FFFFFF;
    white-space: nowrap;
    overflow-x: scroll;
    overflow-y: hidden;
    span{
      width: 120px;
      display: inline-block;
    }

    .acTab {
      position: relative;
      color: #222;
      font-weight: bold;
      &:after {
        content: '';
        display: block;
        position: absolute;
        height: 12px;
        width: 36px;
        border-radius: 2px;
        left: 50%;
        bottom: 10px;
        transform: translateX(-50%);
        background: url("../../assets/images/icon/tab.png") no-repeat;
        background-size: 100% 100%;
      }
    }
  }
}
</style>
